#pragma once

#include <EventLoop.h>
#include <functional>
#include <memory>
#include <thread>
#include <mutex>
#include <condition_variable>

class EventLoopThread
{
    using ThreadInitCallback = std::function<void(EventLoop*)>;

public:
    EventLoopThread(const std::string name, ThreadInitCallback cb = ThreadInitCallback());

    EventLoop *startLoop();

    ~EventLoopThread();

private:
    std::string name_;
    std::mutex mutex_;
    std::condition_variable cond_;
    EventLoop *loop_;
    std::unique_ptr<std::thread> thread_;
    bool existing_;
    ThreadInitCallback cb_;
};